home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_9.zip / CWKTASK.C < prev    next >
C/C++ Source or Header  |  1993-07-27  |  20KB  |  722 lines

  1.  
  2.  
  3. /*
  4.     GWMON Parallel Ada Monitor for 386/486 PCs   
  5.     Copyright (C) 1993, Charles W. Kann  & Michael Bliss Feldman
  6.                         ckann@seas.gwu.edu mfeldman@seas.gwu.edu
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation; either version 2 of the License.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21. */
  22.  
  23. #include "ed.h"
  24. #include "keydef.h"
  25. /*
  26.     I need the variable "exception_trace" from ivars.h.  I don't want
  27.     to use the whole .h, so I am including this one variable here.
  28. */
  29. extern int exception_trace;
  30.  
  31. static int current_task;
  32. static int save_block_number = -1;
  33. static long Run_Total_Time;   /* Total run time (lines) for this run */
  34. static long Run_Current_Time; /* Run time (lines) since last report */
  35. extern rr_flag;
  36. void CWK_SET_TASK();
  37. void CWK_SET_TASK_LINE();
  38. void CWK_GET_KEY();
  39. static void scroll_tasks();
  40.  
  41. void busy_wait(wait_cnt)
  42. int wait_cnt;
  43. {
  44.     int i, cycles;
  45.     cycles = delay_scaling_factor * delay_array[wait_cnt];
  46.     for ( i = 0; i < cycles; ++i );
  47. }
  48.  
  49. void CWK_CREATE_TASK(task_no, task_name, task_file)
  50. int task_no;
  51. char *task_name;
  52. char *task_file;
  53. {
  54.     char msg[100];
  55.     int ch;
  56.  
  57.     if ( task_no > MAX_TSKS ) {
  58.     printf("Can't work with more than %d tasks...", MAX_TSKS-1);
  59.     }
  60.     /*
  61.     Find the task particulars in the task file (For now, hard code them)
  62.     */
  63.     CWK_TASKS[task_no].TN = malloc( strlen(task_name)+1 );
  64.     strcpy( CWK_TASKS[task_no].TN, task_name );
  65.     CWK_TASKS[task_no].FL = 1;
  66.     CWK_TASKS[task_no].LL = 10000;
  67.     CWK_TASKS[task_no].FLOS = 0;
  68.     CWK_TASKS[task_no].CL = 0;
  69.     CWK_TASKS[task_no].MON = CWK_CREATE_MON_WIN(CWK_TASKS[task_no].TN, 
  70.         (monitor_type == 1) ? 1 : 0 );
  71.         CWK_TASKS[task_no].FD = CWK_LOAD_FILE(task_file);
  72. }
  73.  
  74. /*************************************************************************/
  75. /*                                     */
  76. /*    CWK_Switch_Block is used to make sure the correct program block  */
  77. /*    (ie procedure, package, task, etc) is being used.  When a program*/
  78. /*    block becomes current, we want to make sure that we then move to */
  79. /*    use that program block.  Program blocks are entered and exited   */
  80. /*    inta.c.  We call this routine from there.             */
  81. /*                                     */
  82. /*    parameters:                             */
  83. /*        block_number : the block number of this block           */
  84. /*        block_name   : the title of the block (ie proc name)     */
  85. /*        block_file   : file which contains this block            */
  86. /*         enter_or_exit: Are we entering or exiting this block     */
  87. /*                   This is only used in procedure monitoring */
  88. /*                   If this is 1 - exiting, 0 - entering     */
  89. /*                                     */
  90. /*************************************************************************/
  91.  
  92. CWK_Switch_Block( block_number, block_name, block_package, block_file, 
  93.           enter_or_exit )
  94. int block_number, enter_or_exit;
  95. char *block_name, *block_package, *block_file;
  96. {
  97.     FILE_REC_PTR Save_FD;
  98.  
  99.     /*
  100.         In the case of task monitoring, if the new procedure is in
  101.         a different source file from the one currently being used,
  102.         move to that source file.
  103.     */ 
  104.     {
  105.     char msg[80];
  106.     sprintf( msg, "block_number = %d, block_package = %s\n", 
  107.         block_number, block_package );
  108.     _outtext( msg );
  109.     getch();
  110.     }
  111.     if ( task_monitor )
  112.     {
  113.             Save_FD = CWK_TASKS[current_task].FD;
  114.             CWK_TASKS[current_task].FD = CWK_LOAD_FILE(block_file);
  115.             if ( Save_FD != CWK_TASKS[current_task].FD )
  116.                     CWK_TASKS[current_task].FLOS = 0;
  117.     }
  118.  
  119.     /*
  120.         Procedure monitoring
  121.     */
  122.     else
  123.     {
  124.         /*
  125.             The save_block_number remembers the block between
  126.             calls.  The first time through, however, it must be set
  127.         */
  128.         if ( save_block_number == -1 )
  129.             save_block_number = block_number;
  130.  
  131.         /*
  132.             If this block hasn't been created, and we have a valid
  133.             block, create it.
  134.         */
  135.         if  ( CWK_BLKS[block_number].MON == NULL ) 
  136.             CWK_CREATE_BLOCK(block_number, block_name, block_file );
  137.  
  138.         /*
  139.             Only worry about monitor windows if the monitor is
  140.             running.
  141.         */
  142.  
  143.         if ( monitor_type != 1 )
  144.             return;
  145.         
  146.         if ( monitor_window_type == 3 )
  147.         {
  148.             save_block_number = block_number;
  149.             CWK_DRAW_PROC_WIN( CWK_BLKS[block_number].MON, 
  150.                 enter_or_exit );
  151.  
  152.                 CWK_BLKS[save_block_number].FLOS = 0;
  153. #if 0
  154.             CWK_SET_TASK_LINE( CWK_BLKS[block_number].CL, 0 );
  155. #endif
  156.  
  157.             /*
  158.                 If the mode is to be in task step mode,
  159.                 then wait for a key to be pressed to
  160.                 move to the next step, otherwise, wait
  161.                 a second to keep the screen from flashing.
  162.             */
  163.  
  164.             if ( task_step )
  165.                      CWK_GET_KEY( 1 );
  166.             else
  167.                 busy_wait( MAX_DELAY-1 );
  168.         }
  169.         else
  170.             save_block_number = block_number;
  171.             
  172.     }
  173. }
  174.  
  175. CWK_LEAVE_BLOCK( block_number )
  176. int block_number;
  177. {
  178.     if ( monitor_type != 1 )
  179.         return;
  180.     if ( ! task_monitor )
  181.         CWK_REMOVE_BLOCK( CWK_BLKS[block_number].MON);
  182. }
  183.  
  184. /*************************************************************************/
  185. /*************************************************************************/
  186.     
  187. void CWK_DISTROY_TASK(task_no)
  188. int task_no;
  189. {
  190.     CWK_TASKS[task_no].TN = "";
  191.     CWK_TASKS[task_no].FL = 0;
  192.     CWK_TASKS[task_no].LL = 0;
  193.     CWK_DEL_MON_WIN(CWK_TASKS[task_no].MON);
  194. }
  195.     
  196. void CWK_CHANGE_TASK_STAT(task_no, stat, task_name, task_file )
  197. int task_no;
  198. char stat;
  199. char *task_name, *task_file;
  200. {
  201.     int FLOS;
  202.     FLOS = CWK_TASKS[task_no].FLOS;
  203.  
  204.     if ( ! task_monitor )
  205.         return;
  206.  
  207.     CWK_TASKS[task_no].ST = stat;
  208.  
  209.     switch( stat ) {
  210.         case 'C' :      /* Create a new task */
  211.         CWK_CREATE_TASK( task_no, task_name, task_file );
  212.         CWK_TASKS[task_no].ST = '*';
  213.         break;
  214.         case 'A' :     /* Activate a task */
  215.         CWK_SET_TASK( task_no );
  216.         CWK_TASKS[task_no].ST = '*';
  217.         if ( ( task_step ) && ( CWK_TASKS[task_no].MON->WON == 1 ) )
  218.                  CWK_GET_KEY( 1 );
  219.         break;
  220.         case 'S' :    /* Change to a new task */
  221.         CWK_SET_TASK( task_no );
  222.         CWK_TASKS[task_no].ST = '*';
  223.         break;
  224.         case 'D' :    /* Delaying task       */
  225.         if ( monitor_type == 1 )
  226.         {
  227.             CWK_CUR_LINE( CWK_TASKS[task_no].MON, 
  228.                 CWK_TASKS[task_no].CL- FLOS, " D " );
  229.             if ( ( task_step ) && 
  230.                  ( CWK_TASKS[task_no].MON->WON == 1 ) )
  231.                      CWK_GET_KEY( 1 );
  232.         }
  233.         break;
  234.         case 'R' :    /* Waiting Rendezvous  */
  235.         if ( monitor_type == 1 )
  236.         {
  237.             CWK_CUR_LINE( CWK_TASKS[task_no].MON,
  238.                 CWK_TASKS[task_no].CL- FLOS, " R " );
  239.             if ( ( task_step ) && 
  240.                  ( CWK_TASKS[task_no].MON->WON == 1 ) )
  241.                      CWK_GET_KEY( 1 );
  242.         }
  243.         break;
  244.         case 'M' :    /* Rendezvous Met  */
  245.         if ( monitor_type == 1 )
  246.         {
  247.             CWK_CUR_LINE( CWK_TASKS[task_no].MON,
  248.                 CWK_TASKS[task_no].CL- FLOS, " M " );
  249.             if ( ( task_step ) && 
  250.                  ( CWK_TASKS[task_no].MON->WON == 1 ) )
  251.                      CWK_GET_KEY( 1 );
  252.         }
  253.         break;
  254.         case 'E' :    /* Rendezvous Met  */
  255.         CWK_DISTROY_TASK( task_no );
  256.         break;
  257.         }
  258. }
  259.  
  260. void CWK_SET_TASK_LINE( line_no, getkey_or_not )
  261. int line_no, getkey_or_not;
  262. {
  263.     int i;
  264.     int FLOS;
  265.     static text_string[50], format_string[50];
  266.  
  267.     TASK_REC *temp_task;
  268.     int task_no;
  269.  
  270.     if ( task_monitor )
  271.     {
  272.         task_no = current_task;
  273.         temp_task = CWK_TASKS;
  274.     }
  275.     else
  276.     {
  277.         task_no = save_block_number;
  278.         temp_task = CWK_BLKS;
  279.     }
  280.  
  281.         if ( temp_task[task_no].FD->lines_in_file < line_no )
  282.     {
  283.         return;
  284.     }
  285.  
  286.     if ( ( temp_task[task_no].MON->WON != 1 )  ||
  287.          ( monitor_type != 1 ) )
  288.     {
  289.         return;
  290.     }
  291.  
  292.     FLOS = temp_task[task_no].FLOS;
  293.     if ( FLOS != 0 ) 
  294.         CWK_CUR_LINE(temp_task[task_no].MON, 
  295.            temp_task[task_no].CL - FLOS, "   ");
  296.     if (( FLOS == 0 ) ||
  297.        (( line_no < FLOS ) || (line_no > FLOS + WIN_SIZE))) {
  298.         FLOS = line_no - (WIN_SIZE / 2);
  299.         if (FLOS < 1) 
  300.             FLOS = 1;
  301.         temp_task[